import { Module } from "@nestjs/common";
import { MulterModule } from "@nestjs/platform-express";
import { diskStorage } from "multer";
import { extname, join } from "path";
import { UploadController } from "./upload.controller";
import { UploadService } from "./upload.service";
import { MongooseModule } from "@nestjs/mongoose";
import { Upload, UploadSchema } from "./schemas/upload.schema";

 
@Module({
    imports:[
        MongooseModule.forFeature([{ name: Upload.name, schema: UploadSchema }]),
        MulterModule.register({
            storage: diskStorage({
                // 图片存放路径
                destination: join(__dirname, "../public"),
                // 图片文件名
                filename: (_, file, callback) => {
                    const fileName = `${new Date().getTime() + extname(file.originalname)}`;
                    return callback(null, fileName);
                }
            })
        })
    ],
    controllers: [UploadController],
    providers: [UploadService]
})
export class UploadModule { }